package com.network.config;


import com.network.interceptor.InterceptorConfig;
import com.network.interceptor.UpdateUserInfoInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    InterceptorConfig interceptor;

    @Autowired
    UpdateUserInfoInterceptor updateUserInfoInterceptor;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/pictures/**").addResourceLocations("file:///D:/pictures/");
//        registry.addResourceHandler("/pictures/**").addResourceLocations("classpath:/pictures/");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {




        InterceptorRegistration interceptorRegistration = registry.addInterceptor(interceptor);
        interceptorRegistration.addPathPatterns("/**");
        interceptorRegistration.excludePathPatterns("/login"
                , "/register"
                , "/getImage"
                , "/check"
                , "/**/*.js"
                , "/**/*.css"
                , "/**/*.html"
                , "/**/*.png"
                , "/**/*.svg"
                , "/**/*.jpg"
                , "/**/*.jpeg"
                , "/**/*.eot"
                , "/**/*.svg"
                , "/**/*.ttf"
                , "/**/*.woff"
                , "/**/*.woff2"
                , "/**/*.gif");



        InterceptorRegistration interceptorRegistration1 = registry.addInterceptor(updateUserInfoInterceptor);
        interceptorRegistration1.addPathPatterns("/**");
        interceptorRegistration1.excludePathPatterns("/login"
                , "/"
                , "/exit"
                , "/tmp"
                , "/user/up"
                , "/userr"
                , "/userInfo"
                , "/register"
                , "/getImage"
                , "/check"
                , "/**/*.js"
                , "/**/*.css"
                , "/**/*.html"
                , "/**/*.png"
                , "/**/*.svg"
                , "/**/*.jpg"
                , "/**/*.jpeg"
                , "/**/*.eot"
                , "/**/*.svg"
                , "/**/*.ttf"
                , "/**/*.woff"
                , "/**/*.woff2"
                , "/**/*.gif");





    }
}
